using Domain.Entities;
using Domain.Entities.Enums;
using Domain.Services;
using System;

namespace UserInterface.Admin
{
    public partial class ManageUsers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // TODO: Make a better ban system
            if (Request.QueryString["userId"] != null)
            {
                User user = UserService.GetById(Convert.ToInt32(Request.QueryString["userId"]));
                if (user.Status == UserStatus.Disabled)
                {
                    UserService.UpdateStatus(user, UserStatus.Activated);
                }
                else
                {
                    UserService.UpdateStatus(user, UserStatus.Disabled);
                }
            }
        }

        protected void SearchButton_Click(object sender, EventArgs e)
        {
            string searchTerm = SearchTermTextBox.Text.Trim();

            if (searchTerm != "")
            {
                UsersRepeater.DataSource = UserService.GetMatchingUsername(searchTerm);
                UsersRepeater.DataBind();
            }
        }
    }
}
